﻿package com.flashframeless.gallery {

	import com.flashframeless.gallery.modules.images.Images;
	import com.flashframeless.gallery.modules.thumbs.Thumbs;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import gs.TweenLite;
	import gs.easing.Quint;
	
	public class Gallery extends MovieClip {
		
		public var thumbs	: Thumbs;
		public var images	: Images;
		public var item		: Object;
		
		public function Gallery() {
			
			instanciate();
			
		}
		
		private function instanciate():void {
			
			thumbs = thumbsMc;
			images = imagesMc;
			
			setupInteractions();
			
		}
		
		private function setupInteractions():void {
			
			thumbs.addEventListener( Event.CHANGE, openImages );
			images.addEventListener( Event.CLOSE, openThumbs );
			
		}
		
		private function openImages( evt:Event ):void {
			
			images.activeListeners( true );
			thumbs.activeListeners( false );
			
			images.data = item;
			
			TweenLite.to( thumbs, .5, { autoAlpha:0, ease:Quint.easeOut } );
			TweenLite.to( images, .5, { autoAlpha:1, ease:Quint.easeOut, delay:.2 } );
			
		}
		
		private function openThumbs( evt:Event ):void {
			
			thumbs.activeListeners( true );
			images.activeListeners( false );
			
			TweenLite.to( thumbs, .5, { autoAlpha:1, ease:Quint.easeOut, delay:.2 } );
			TweenLite.to( images, .5, { autoAlpha:0, ease:Quint.easeOut, onComplete:function() {
				
				images.clear();
				
			} } );
			
		}
		
	}
	
}